package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品管理
 */
@RequestMapping("/admin/dish")
@RestController
@Slf4j
@Api(tags = "菜品相关接口")
public class DishController {

    @Autowired
    private DishService dishService;
    @Autowired
    private CategoryService categoryService;

    /**
     * 新增菜品
     *
     * @param dish
     * @return
     */
    @PostMapping
    @ApiOperation("新增菜品")
    public Result save(@RequestBody DishDTO dish) {
        dishService.save(dish);
        return Result.success("文件上传失败！");
    }

    /**
     * 分类分页查询
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO){
        log.info("菜品分页查询：{}", dishPageQueryDTO);
        PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 菜品删除
     *
     * @param
     * @return
     */
    @DeleteMapping
    @ApiOperation("菜品删除")
    public Result deleteById(@RequestParam List<Long> ids) {
        log.info("菜品批量删除：{}", ids);
        if (ids == null || ids.size() < 1) {
            return Result.error("菜品id不能为空！");
        }
        dishService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 菜品查询
     *
     * @param
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("菜品查询")
    public Result seletById(@PathVariable Long id) {
        if (id == null) {
            return Result.error("菜品id不能为空！");
        }
        return Result.success(dishService.selectById(id));
    }


}
